﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Data;
public partial class user_setprofile : Wozuji.Logic.PageLogin
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Header.Title = "足迹网 设置用户基本信息";

        try
        {
            if (!IsPostBack)
            {//数据绑定
                Wozuji.Model.Member_t mb = new Wozuji.Model.Member_t();
                Wozuji.DAL.Member_t mbdal = new Wozuji.DAL.Member_t();
                mb = mbdal.GetModel_ByMemberId(Convert.ToInt32(Session["userid"]));

                workfor.Text = mb.Member_occupation;
                if (!mb.Member_FriendName.Equals(""))
                {
                    realName.Text = mb.Member_FriendName;
                }
                if (!mb.Member_birthday.Equals("1900-01-01"))
                {
                    birthday.Text = mb.Member_birthday.ToString();
                }
                //绑定地区
                //得到省

                DataSet dsSheng = new DataSet();
                dsSheng = new Wozuji.BLL.region_t().GetList("rtrim(region_code) like'%0000' order by rtrim(region_code) ");
                DropDownList1.Items.Clear();
                for (int i = 0; i < dsSheng.Tables[0].Rows.Count; i++)
                {
                    ListItem li = new ListItem();
                    li.Text = dsSheng.Tables[0].Rows[i]["region_name"].ToString();
                    li.Value = dsSheng.Tables[0].Rows[i]["region_code"].ToString();
                    if (!mb.Member_ComeFrom.ToString().Equals("0"))
                    {
                        String aa = mb.Member_ComeFrom.ToString().Substring(0, 6);
                        String bb = mb.Member_ComeFrom.ToString().Substring(6, 3);
                        if (mb.Member_ComeFrom.ToString().Substring(0, 6).Equals(dsSheng.Tables[0].Rows[i]["region_code"].ToString().Trim()))
                        {
                            li.Selected = true;
                        }
                    }
                    DropDownList1.Items.Add(li);
                }
                //得到市
                if (!mb.Member_ComeFrom.ToString().Equals("0"))
                {
                    DataSet dsshi = new Wozuji.BLL.region_t().GetList("rtrim(region_code) not like'%0000' and rtrim(region_code) like'" + mb.Member_ComeFrom.ToString().Substring(6, 3) + "%'");
                    for (int i = 0; i < dsshi.Tables[0].Rows.Count; i++)
                    {
                        ListItem li = new ListItem();
                        li.Text = dsshi.Tables[0].Rows[i]["region_name"].ToString();
                        li.Value = dsshi.Tables[0].Rows[i]["region_code"].ToString();
                        if (!mb.Member_ComeFrom.ToString().Equals("0"))
                        {
                            if (mb.Member_ComeFrom.ToString().Substring(6, 6).Equals(dsshi.Tables[0].Rows[i]["region_code"].ToString().Trim()))
                            {
                                li.Selected = true;
                            }
                        }
                        DropDownList2.Items.Add(li);
                    }
                }

                //绑定职业
                DataSet dswork = new Wozuji.BLL.datadic_t().GetList("datadic_typecode=2 order by datadic_value");
                for (int j = 0; j < dswork.Tables[0].Rows.Count; j++)
                {
                    ListItem li = new ListItem();
                    li.Text = dswork.Tables[0].Rows[j]["datadic_name"].ToString();
                    li.Value = dswork.Tables[0].Rows[j]["datadic_value"].ToString();
                    if (!mb.Member_Workfor.Equals("0"))
                    {
                        if (mb.Member_Workfor.Equals(dswork.Tables[0].Rows[j]["datadic_value"].ToString()))
                        {
                            li.Selected = true;
                        }
                    }
                    work.Items.Add(li);

                }
                //绑定性别
                sex.Items.Clear();
                DataSet dssex=new Wozuji.BLL.datadic_t().GetList("datadic_typecode=1 order by datadic_value");
                for (int k = 0; k < dssex.Tables[0].Rows.Count; k++)
                {
                    ListItem li = new ListItem();
                    li.Text = dssex.Tables[0].Rows[k]["datadic_name"].ToString();
                    li.Value = dssex.Tables[0].Rows[k]["datadic_value"].ToString();

                    if (mb.Member_Sex.Equals(dssex.Tables[0].Rows[k]["datadic_value"].ToString()))
                    {
                         li.Selected = true;
                    }
                   
                    sex.Items.Add(li);

                }

            }

        }
        catch (Exception ex)
        {
            //Response.Redirect("/u/userlogin.aspx");
        }




    }
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {


        if (Regex.IsMatch(realName.Text.Trim(), "[\u4e00-\u9fa5]"))
        {
            realnameMsg.Text = "";
        }
        else
        {
            realnameMsg.Text = "输入必须是中文";
        }



    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!DropDownList1.SelectedItem.Value.Equals("000000"))
        {
            Wozuji.BLL.region_t reg = new Wozuji.BLL.region_t();
            DataSet ds = reg.GetList("rtrim(region_code) like'" + DropDownList1.SelectedItem.Value.Substring(0, 2) + "%' and rtrim(region_code) like'%00'and rtrim(region_code) not like'%0000'");
            //清空下拉列表
            DropDownList2.Items.Clear();
            //绑定下拉列表
            DropDownList2.DataSource = ds.Tables[0];
            DropDownList2.DataTextField = "region_name";
            DropDownList2.DataValueField = "region_code";
            DropDownList2.DataBind();



        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //得到用户信息
        Wozuji.Model.Member_t mb = new Wozuji.Model.Member_t();
        Wozuji.BLL.Member_t mbbill = new Wozuji.BLL.Member_t();
        mb = mbbill.GetModel(Convert.ToInt32(Session["userid"].ToString()));
        mb.Member_Sex = sex.SelectedItem.Value.ToString();
        mb.Member_FriendName = realName.Text.ToString();
        mb.Member_Workfor = work.SelectedItem.Value;
        if (DropDownList2.Items.Count > 0)
        {
            mb.Member_ComeFrom = DropDownList1.SelectedItem.Value.ToString().Trim() + DropDownList2.SelectedItem.Value.ToString().Trim();
        }
        else
        {
            mb.Member_ComeFrom = DropDownList1.SelectedItem.Value.ToString().Trim();
        }
        mb.Member_occupation = workfor.Text.ToString();
        mb.Member_Money = mb.Member_Money + 1;
        mb.Member_ActiveValue = mb.Member_ActiveValue + 1;
        mbbill.Update(mb);
        Response.Redirect("/u/setprofile.aspx");
    }
}
